/**
 * Created by Administrator on 2017/7/3 0003.
 */
require(["jquery","bbcare"],function($,$bb) {
    var URL = $bb.baseUrl("department")+"followup/service";
    $bb.ajax({
        url: URL + "/department/basicinfo/detail",
        data: JSON.stringify({
            data: {}
        }),
        success: function (data) {
            if(data.success){
                if(data.data.qrCode){
                    $(".img").html('<img class="qr_img" src="'+data.data.qrCode+'"/>').css("background-color","#fff");
                    var img_src = $('.qr_img')[0].src;
                    if(browserIsIe()){//假如是ie浏览器
                        $('.down_qr').on('click',function(){
                            img_src = $('.qr_img')[0].src;
                            DownLoadReportIMG(img_src);
                        });
                    }else{
                        $('.down_qr').attr('download',img_src);
                        $('.down_qr').attr('href',img_src);
                    }
                }else{
                    $(".img").html('<i class="fa fa-picture-o" aria-hidden="true"></i>').css("background-color","#e5e5e5");
                }

                function DownLoadReportIMG(imgPathURL) {
                    //如果隐藏IFRAME不存在，则添加
                    if (!document.getElementById("IframeReportImg"))
                        $('<iframe style="display:none;" id="IframeReportImg" name="IframeReportImg" onload="DoSaveAsIMG();" width="0" height="0" src="about:blank"></iframe>').appendTo("body");
                    if (document.all.IframeReportImg.src != imgPathURL) {
                        //加载图片
                        document.all.IframeReportImg.src = imgPathURL;
                    }else {
                        //图片直接另存为
                        DoSaveAsIMG();
                    }
                }
                function DoSaveAsIMG() {
                    if (document.all.IframeReportImg.src != "about:blank")
                        window.frames["IframeReportImg"].document.execCommand("SaveAs");
                }
                //判断是否为ie浏览器
                function browserIsIe() {
                    if (!!window.ActiveXObject || "ActiveXObject" in window)
                        return true;
                    else
                        return false;
                }
            }
        }
    });
})